package cemp.rmq;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class StockRMQDirectExchangeConfig {

    //死信
    @Bean("deadQueue")
    public Queue deadQueue() {
        return new Queue("dead_queue");
    }

    @Bean("deadExchange")
    public Exchange deadExchange() {
        return ExchangeBuilder.directExchange("dead_exchange").build();
    }

    @Bean("deadQueueBind")
    public Binding deadQueueBind() {
        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with("dead").noargs();
    }

    //

    @Bean
    DirectExchange baseStockHistoryExchange() {
        //  return new DirectExchange("TestDirectExchange",true,true);
        return new DirectExchange("baseStockHistoryExchange",true,false);
    }

    @Bean
    TopicExchange stockCurrentExchange() {
        return new TopicExchange("stockCurrentExchange");
    }

    @Bean
    TopicExchange stockKpiExchange() {
        return new TopicExchange("stockKpiExchange");
    }

    @Bean
    public Queue shCurrentQueue() {
        return QueueBuilder.durable(StockRMQConstant.TOPIC_CURRENT_SH)
                .deadLetterExchange("dead_exchange") // 设置死信交换机
                .deadLetterRoutingKey("dead") // 设置死信队列的路由键为dead
                .build();
    }
    @Bean
    public Queue szCurrentQueue() {
        return QueueBuilder.durable(StockRMQConstant.TOPIC_CURRENT_SZ)
                .deadLetterExchange("dead_exchange") // 设置死信交换机
                .deadLetterRoutingKey("dead") // 设置死信队列的路由键为dead
                .build();
    }
    @Bean
    public Queue shKpiQueue() {
        return new Queue(StockRMQConstant.TOPIC_KPI_SH);
    }
    @Bean
    public Queue szKpiQueue() {
        return new Queue(StockRMQConstant.TOPIC_KPI_SZ);
    }

    @Bean
    Binding bindCurrentSH() {
        return BindingBuilder.bind(shCurrentQueue()).to(stockCurrentExchange()).with("topic.stock.current.sh.#");
    }
    @Bean
    Binding bindCurrentSZ() {
        return BindingBuilder.bind(szCurrentQueue()).to(stockCurrentExchange()).with("topic.stock.current.sz.#");
    }

    @Bean
    Binding bindKpiSH() {
        return BindingBuilder.bind(shKpiQueue()).to(stockKpiExchange()).with("topic.stock.kpi.sh.#");
    }
    @Bean
    Binding bindKpiSZ() {
        return BindingBuilder.bind(szKpiQueue()).to(stockKpiExchange()).with("topic.stock.kpi.sz.#");
    }



}
